package com.zqxx.examine.portal.security;


import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

import org.springframework.security.crypto.password.PasswordEncoder;

public class StandardPasswordEncoderForSha1
  implements PasswordEncoder
{
  public String encode(CharSequence rwPassword)
  {
    MessageDigest mDigest = null;
    try
    {
      mDigest = MessageDigest.getInstance("SHA1");
    }
    catch (NoSuchAlgorithmException e)
    {
      e.printStackTrace();
    }
    byte[] result = mDigest.digest(rwPassword.toString().getBytes());
    StringBuffer sb = new StringBuffer();
    for (int i = 0; i < result.length; i++) {
      sb.append(Integer.toString((result[i] & 0xFF) + 256, 16).substring(1));
    }
    return sb.toString();
  }
  
  public boolean matches(CharSequence rwPassword, String password)
  {
    return rwPassword.equals(password);
  }
}

